package web.feedbackpanel;

import org.apache.wicket.Component;
import org.apache.wicket.ajax.AjaxRequestTarget;
import org.apache.wicket.ajax.markup.html.form.AjaxSubmitLink;
import org.apache.wicket.markup.html.WebPage;
import org.apache.wicket.markup.html.form.Form;
import org.apache.wicket.markup.html.form.RequiredTextField;
import org.apache.wicket.markup.html.panel.FeedbackPanel;
import org.apache.wicket.model.PropertyModel;

public class FeedbackHome extends WebPage{
	private static final long serialVersionUID = 1L;
	private FeedbackPanel feedback;
	private String algo;

	public FeedbackHome() {
		this.setAlgo("");
		Form<Void> form = new Form<Void>("form");
		this.add(form.add(
			feedback = new FeedbackPanel("feedback"),
			texto(),
			boton()
		));
		feedback.setOutputMarkupId(true);
	}
	
	private Component texto() {
		PropertyModel<String> modelo = new PropertyModel<String>(this, "algo");
		return new RequiredTextField<String>("texto", modelo);
	}

	private Component boton() {
		return new AjaxSubmitLink("boton") {
			private static final long serialVersionUID = 1L;

			@Override
			protected void onSubmit(AjaxRequestTarget target, Form<?> arg1) {
				success("sucess!");
				info("info");
				target.add(feedback);
			}
			
			@Override
			protected void onError(AjaxRequestTarget target, Form<?> form) {
				target.add(feedback);
			}
		};
	}

	
	//setters&getters
	public void setAlgo(String algo) {
		this.algo = algo;
	}
	public String getAlgo() {
		return algo;
	}
}